<template>
	<view class="full-page root-style">
		<view class="h-10px"></view>
		<u-section title="" :show-line="false" color="#F08519" :right="false">
			<template #right>
				<view class="flex items-center" @tap="show=true">
					<template v-if="StartDate">
						<text class="mr-5px" style="color: #F08519;">{{StartDate}}</text>至
						<text class="ml-5px mr-5px" style="color: #F08519;">{{StartDate}}</text>
					</template>
					<text v-else>日期筛选</text>
					<u-icon name="calendar" style="vertical-align: middle; margin-top: 2px;" :size="40"></u-icon>
				</view>
			</template>
		</u-section>
		<view class="h-10px"></view>
		<u-table>
			<u-tr class="u-tr">
				<u-td width="100px" class="u-td">姓名</u-td>
				<u-td class="u-td">{{studentName}}</u-td>
			</u-tr>
			<u-tr class="u-tr">
				<u-td width="100px" class="u-td">词汇统计</u-td>
				<u-td class="u-td">熟悉词</u-td>
				<u-td class="u-td">1-4阶</u-td>
				<u-td class="u-td">5-7阶</u-td>
				<u-td class="u-td">8-9阶</u-td>
				<u-td class="u-td">合计</u-td>
			</u-tr>
			<u-tr class="u-tr">
				<u-td width="100px" class="u-td">学习量</u-td>
				<u-td class="u-td">{{countObj.remberLv0Cnt}}</u-td>
				<u-td class="u-td">{{countObj.remberLv4Cnt}}</u-td>
				<u-td class="u-td">{{countObj.remberLv7Cnt}}</u-td>
				<u-td class="u-td">{{countObj.remberLv9Cnt}}</u-td>
				<u-td class="u-td">{{countObj.remberCnt}}</u-td>
			</u-tr>
			<u-tr class="u-tr">
				<u-td width="100px" class="u-td">复习量</u-td>
				<u-td class="u-td">{{countObj.reviewLv0Cnt}}</u-td>
				<u-td class="u-td">{{countObj.reviewLv4Cnt}}</u-td>
				<u-td class="u-td">{{countObj.reviewLv7Cnt}}</u-td>
				<u-td class="u-td">{{countObj.reviewLv9Cnt}}</u-td>
				<u-td class="u-td">{{countObj.reviewCnt}}</u-td>
			</u-tr>
		</u-table>
		<u-calendar v-model="show" mode="range" @change="change"></u-calendar>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import { dateFormat, ktluser, ktlapi, getVersion, OT, lodash } from '@/utils';
	const user = ktluser.getUser(false)
	
	// 通过传参拿到的学生AccountId;
	let queryStudentAccountId = null;
	let StartDate = ref('');
	let EndDate = ref('');
	const show = ref(false);
	const studentName = ref('_');
	const countObj = ref({
		remberCnt: 0,
		remberLv0Cnt: 0,
		remberLv4Cnt: 0,
		remberLv7Cnt: 0,
		remberLv9Cnt: 0,
		reviewCnt: 0,
		reviewLv0Cnt: 0,
		reviewLv4Cnt: 0,
		reviewLv7Cnt: 0,
		reviewLv9Cnt: 0
	});
	const nowDate = dateFormat(new Date());
	StartDate.value = nowDate.toString();
	EndDate.value = nowDate.toString();
	
	
	function change(e: any) {
		// endDate: "2025-08-21"
		// endDay: 21
		// endMonth: 8
		// endWeek: "星期四"
		// endYear: 2025
		// startDate: "2025-07-01"
		// startDay: 1
		// startMonth: 7
		// startWeek: "星期二"
		// startYear: 2025
		StartDate.value = e.startDate;
		EndDate.value = e.endDate;
		
		getData();
	}
	
	function getData() {
		ktlapi({
			apiurl: OT.CommandSet,
			action: 'Cus_GetStudentProcessDataCnt',
			data: {
				StudentAccountId: queryStudentAccountId || user.AccountID,
				StartDate: StartDate.value + ' 00:00:00',
				EndDate: EndDate.value + ' 23:59:59'
			}
		}).then((resp: any) => {
			studentName.value = lodash.get(resp, 'data.tables[0].table[0].StudentName', '')
			const list = lodash.get(resp, 'data.tables[1].table', [])
			const remberList = list.filter((item: any) => item.ReviewTimer === 0);
			const reviewList = list.filter((item: any) => item.ReviewTimer > 0);
			
			countObj.value.remberCnt = remberList.length;
			countObj.value.reviewCnt = reviewList.length;
			countObj.value.remberLv0Cnt = remberList.filter((item: any) => item.LostLv === 0).length;
			countObj.value.remberLv4Cnt = remberList.filter((item: any) => item.LostLv > 0 && item.LostLv <= 4).length;
			countObj.value.remberLv7Cnt = remberList.filter((item: any) => item.LostLv > 4 && item.LostLv <= 7).length;
			countObj.value.remberLv9Cnt = remberList.filter((item: any) => item.LostLv > 7).length;
			countObj.value.reviewLv0Cnt = reviewList.filter((item: any) => item.LostLv === 0).length;
			countObj.value.reviewLv4Cnt = reviewList.filter((item: any) => item.LostLv > 0 && item.LostLv <= 4).length;
			countObj.value.reviewLv7Cnt = reviewList.filter((item: any) => item.LostLv > 4 && item.LostLv <= 7).length;
			countObj.value.reviewLv9Cnt = reviewList.filter((item: any) => item.LostLv > 7).length;
		})
	}
	
	onLoad((query: any) => {
		if (lodash.get(query, 'AccountId')) {
			queryStudentAccountId = query.AccountId;
		}
	})
	
	onMounted(() => {
		getData();
	})
</script>

<style lang="scss" scoped>
	.full-page{
		padding-left: 15px;
		padding-right: 15px;
	}
	
	.u-td{
		font-size: var(--text-14) !important;
	}
	.none-b{
		border: none !important;
	}
	.none-lb{
		border-left: none !important;
	}
	.none-rb{
		border-right: none !important;
	}
	.none-bb{
		border-bottom: none !important;
	}
	
</style>